// url存储key
const urlLocalStorageKey = 'newTab-key-89s0dfysahf82h394uh'
const iframeLocalStorageKey = 'newTab-iframe-89s0dfysahf82h394uh'
// 监听input输入，设置url
const inputElement = document.getElementById('urlInput')
inputElement.value = window.localStorage.getItem(urlLocalStorageKey) || null
inputElement.addEventListener('input', function (event) {
    window.localStorage.setItem(urlLocalStorageKey, event.target.value)
})
// 是否在frame中打开
const checkboxElement = document.getElementById('urlCheckbox')
let checked = window.localStorage.getItem(iframeLocalStorageKey)
checkboxElement.checked = checked === 'false' ? false : true
checkboxElement.addEventListener('click', function () {
    window.localStorage.setItem(iframeLocalStorageKey, checkboxElement.checked ? 'true' : 'false')
})
// 绑定快捷设置按钮事件
const bingBtns = {
    setWelcome: '',
    setEmpty: '空白页',
}
for (let key in bingBtns) {
    document.getElementById(key).addEventListener('click', function () {
        inputElement.value = bingBtns[key]
        window.localStorage.setItem(urlLocalStorageKey, bingBtns[key])

        let checked = key === 'setDefault'
        checkboxElement.checked = checked
        window.localStorage.setItem(iframeLocalStorageKey, checked)
    })
}


